package edu.hawaii.senin.iclouds.basics;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;


/**
 * Tests normal Atom operations.
 * 
 * @author Administrator.
 * 
 */
public class TestAtom {
  /**
   * test Atom1.
   */
  private Atom Atom1;
  /**
   * test Atom2.
   */
  private Atom Atom2;
  /**
   * test Abundance1.
   */
  private final Double Abundance1 = Double.valueOf(0.33);
  /**
   * test Velocity1.
   */
  private final Double Velocity1 = Double.valueOf(5.33);

  /**
   * test fractional abundance.
   */
  private final Double FAbundance1 = Double.valueOf(0.3);

  /**
   * Little test fixture.
   */
  @Before
  public void runBeforeEachTest() {
    Atom1 = new Atom();
    Atom2 = new Atom();
  }

  /**
   * Tests abundance setter and getter.
   * 
   */
  @Test
  public void testSetAndGetAbundance() {
    Atom1.setAbundance(Abundance1);
    assertEquals("Testing value operations.", Atom1.getAbundance().doubleValue(), Abundance1
        .doubleValue());
  }

  /**
   * Tests velocity setter and getter.
   * 
   */
  @Test
  public void testSetAndGetVelocity() {
    Atom1.setVelocity(Velocity1);
    assertEquals("Testing velocity operations.", Atom1.getVelocity().doubleValue(), Velocity1
        .doubleValue());
  }

  /**
   * Tests fractional abundance setter and getter.
   * 
   */
  @Test
  public void testSetAndGetFAbundance() {
    Atom1.setFraction(FAbundance1);
    assertEquals("Testing fractional abundance operations.", Atom1.getFraction().doubleValue(),
        FAbundance1.doubleValue());
  }

  /**
   * Tests name setter and getter.
   * 
   */
  @Test
  public void testSetAndGetName() {
    Atom1.setName("H");
    assertEquals("Testing equals method.", Atom1.getName(), "H");
  }

  /**
   * Tests atom comparison.
   * 
   */
  @Test
  public void testComparisons() {
    Atom1.setName("H");
    Atom2.setName("H");
    assertEquals("Testing equal operations", true, Atom1.equals(Atom2));

    Atom2.setName("C");
    assertEquals("Testing comparison operations", false, Atom1.equals(Atom2));

    assertEquals("Testing comparison operations", true, Atom2.compareTo(Atom1) < 0);
    assertEquals("Testing comparison operations", true, Atom1.compareTo(Atom2) > 0);
    assertEquals("Testing hash code operations", true, Atom1.hashCode() == Atom1.hashCode());
    assertEquals("Testing hash code operations", false, Atom1.hashCode() == Atom2.hashCode());

  }

}
